package com.atguigu.study.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

@Slf4j
public class testSpringELDemo {
    public static void main(String[] args) {
        log.info("log:{}", "abcd");
        System.out.println();
        //1.String.format占位符替换
        String study = String.format("%s,java", "尚硅谷 study");
        System.out.println(study);
        System.out.println();
        //2.SpringELExpress表达式，#号后面的内容可以被具体值替换
        String var="#userId";
        SpelExpressionParser spelExpressionParser = new SpelExpressionParser();
        Expression expression = spelExpressionParser.parseExpression(var);


        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setVariable("userId","1234");
        String string = expression.getValue(context).toString();
        System.out.println(string);
    }
}
